<%@page import="java.text.*"%>
<%@ page language="java" import="java.util.*,news.dao.*,news.pojo.*,news.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>news_control.jsp</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    request.setCharacterEncoding("UTF-8");
    try{//增加评论
    String cnid=request.getParameter("nid");
    String ccontent=request.getParameter("ccontent");
    Date cdate=new Date();
    SimpleDateFormat fff=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String tt=fff.format(cdate);
    //String cip=request.getParameter("cip");
    String cip=request.getRemoteAddr();
    String cauthor=request.getParameter("cauthor");
   
    Comments comment=new Comments();
    comment.setCnid(Integer.parseInt(cnid));
    comment.setCcontent(ccontent);
    comment.setCdate(cdate);
    comment.setCip(cip);
    comment.setCauthor(cauthor);
    int addcomment= CommentDao.cd.add(comment);
    if(addcomment==1){
    out.print("<script>location='news.jsp?nid="+cnid+"';alert('评论添加成功！');</script>");   
    }else{out.print("<script>alert('评论添加失败！');location='news.jsp?nid="+cnid+"';</script>");   }
   }catch(Exception e){}%>
   
   <% 
   try{// 删除新闻
   String delnid=request.getParameter("delnid");
   News delnew=new News();
  int delresult= NewsDao.nd.del(Integer.parseInt(delnid));
   if(delresult==1){
out.print("<script>alert('成功删除新闻！');location='admin.jsp';</script>");}
else{
out.print("<script>alert('删除新闻失败！');location='admin.jsp';</script>");}
 }catch(Exception e){}  %>

  </body>
</html>
